package com.inhg.inhg_android;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.inhg.inhg_android.net.BaseObserver;
import com.inhg.inhg_android.net.interfaces.LoadingIf;
import com.inhg.inhg_android.net.catchers.ExceptrionCatcher;
import com.inhg.inhg_android.net.RxHttpUtils;
import com.inhg.inhg_android.net.catchers.ThreadCatcher;
import com.inhg.inhg_android.net.catchers.TransformCatcher;
import com.orhanobut.logger.Logger;

import io.reactivex.annotations.NonNull;

public class MainActivity extends AppCompatActivity implements LoadingIf{
    private ProgressDialog dialog;
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dialog = new ProgressDialog(this);

        Button loginBtn = (Button) findViewById(R.id.login);
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RxHttpUtils
                        .getInstance()
                        .create(Api.class)
                        .getFonts()
                        .compose(new ThreadCatcher<Font>())
                        .compose(new ExceptrionCatcher<Font>())
                        .compose(new TransformCatcher<Font>(MainActivity.this))
                        .subscribe(new BaseObserver<Font>() {
                            @Override
                            public void showError(String errorMsg) {
                                Logger.e(errorMsg);
                            }

                            @Override
                            public void onNext(@NonNull Font font) {
                                Logger.d(font);
                            }
                        });







            }
        });
    }

    @Override
    public void showLoading() {
        dialog.show();

    }

    @Override
    public void hiddenLoading() {
        dialog.dismiss();

    }
}
